package com.database;

import java.util.HashMap;
import java.sql.*;


/**
 * @author mayh
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Test {
	
	public HashMap numbers = new HashMap();
	public int     i=0;
	private Mtree mtree;
	
	public void Test()
	{
		//HashMap numbers= new HashMap();
	}
	
	public String  getMeBranch(String Branchid) throws SQLException{
		   
			DataBase db2=new DataBase();
			ResultSet rst2 = null;
			String sql="select ID,Branchid,branchname,parentBranchid,BranchLevel,BranchAdmin,BranchAdminTel from  dbo.CQMS_Branch where BranchID='"+Branchid+"'";
			rst2 = db2.executeQuery(sql);
			//System.out.println(sql);
			
			while(rst2.next()){
				
				//System.out.println(""+i);
				int  id=rst2.getInt("ID");
				String branchid = rst2.getString("branchid");
				String branchname = rst2.getString("branchname");
				String parentBranchid = rst2.getString("parentBranchid");
				String BranchLevel=rst2.getString("BranchLevel");
				String BranchAdmin=rst2.getString("BranchAdmin");
				String BranchAdminTel=rst2.getString("BranchAdminTel");
				 
				 mtree=new Mtree();
				 mtree.setID(id);
				 mtree.setBranchid(branchid);
				 mtree.setParentBranchid(parentBranchid);
				 mtree.setBranchname(branchname);
				 mtree.setBranchLevel(BranchLevel);
				 mtree.setBranchAdmin(BranchAdmin);
				 mtree.setBranchAdminTel(BranchAdminTel);
				 
				 
				 i++;
				 numbers.put(new Integer(i),mtree);				
			}
			rst2.close();
			db2.closeStmt();
			db2.closeConn();
		
		return "";
	}
	
	
	public String  getBranch(String Branchid) throws SQLException{
		   
	
		   
		
		
			DataBase db2=new DataBase();
			ResultSet rst2 = null;
			String sql="select ID,Branchid,branchname,parentBranchid,BranchLevel,BranchAdmin,BranchAdminTel from  dbo.CQMS_Branch where ParentBranchID='"+Branchid+"'";
			rst2 = db2.executeQuery(sql);
			System.out.println(sql);
			
			while(rst2.next()){
				
				System.out.println(""+i);
				int  id=rst2.getInt("ID");
				String branchid = rst2.getString("branchid");
				String branchname = rst2.getString("branchname");
				String parentBranchid = rst2.getString("parentBranchid");
				String BranchLevel=rst2.getString("BranchLevel");
				String BranchAdmin=rst2.getString("BranchAdmin");
				String BranchAdminTel=rst2.getString("BranchAdminTel");
				 
				 mtree=new Mtree();
				 mtree.setID(id);
				 mtree.setBranchid(branchid);
				 mtree.setParentBranchid(parentBranchid);
				 mtree.setBranchname(branchname);
				 mtree.setBranchLevel(BranchLevel);
				 mtree.setBranchAdmin(BranchAdmin);
				 mtree.setBranchAdminTel(BranchAdminTel);
				 
				 
				 i++;
				 numbers.put(new Integer(i),mtree);
				 getBranch(rst2.getString("branchid"));					
				
				
			}
			rst2.close();
			db2.closeStmt();
			db2.closeConn();
		
		return "";
	}
	
	public static void main(String []args) throws SQLException {
		int j=0;
		String n1="";
	
	
		Test 	mTest = new Test();
		
		mTest.getMeBranch("99");
		mTest.getBranch("99");
		
		//HashMap numbers=new Test().numbers;
		
		System.out.println("mTest i =" + mTest.i);
		
		for(j=1;j<=mTest.i;j++)
		{
			Mtree  mm = (Mtree) mTest.numbers.get(new Integer(j));
			
			System.out.println("branchid =" + mm.getBranchid()+" parentBranchid="+mm.getParentBranchid()+"  "+mm.getBranchname());
		}
}
	}
